package me.zk.practice1.hw;

import java.util.*;

public class HWBJ13 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] s = scanner.nextLine().split(" ");
        if (s.length < 5) {
            System.out.println("NO");
        }
        int[] nums = new int[16];
        for (int i = 0; i < s.length; i++) {
            String a = s[i];
            if ("A".equals(a)||"J".equals(a)||"Q".equals(a)||"K".equals(a)) {
                switch (a){
                    case "A":
                        nums[14]++;break;
                    case "J":
                        nums[11]++;break;
                    case "Q":
                        nums[12]++;break;
                    case "K":
                        nums[13]++;break;
                }
            } else {
                int b = Integer.parseInt(a);
                nums[b]++;
            }
        }
        boolean flag = true;
        List<List<Integer>> all = new ArrayList<>();
        while (flag) {
            List<Integer> list = new ArrayList<>();
            int count = 0;
            for (int i = 3; i < 16; i++) {
                if (nums[i] > 0) {
                    list.add(i);
                } else {
                    //说明构成顺子
                    if (list.size() >= 5) {
                        all.add(new ArrayList<>(list));
                        count++;
                        for (int j : list) {
                            nums[j]--;
                        }
                    }
                    list.clear();
                }
            }
            if (count == 0) {
                flag = false;
            }
        }
        for (List<Integer> list : all) {
            StringBuffer stringBuffer = new StringBuffer();
            for (int i = 0; i < list.size(); i++) {
                stringBuffer.append(getChar(list.get(i)));
                if (i!=list.size()-1){
                    stringBuffer.append(" ");
                }
            }
            System.out.println(stringBuffer);
        }

    }

    public static String getChar(int i) {
        switch (i){
            case 11:return "J";
            case 12:return "Q";
            case 13:return "K";
            case 14:return "A";
            default:return String.valueOf(i);
        }
    }

}
